#include "Ennemy.h"

using namespace sf;

Ennemy::Ennemy(Vector2f dimension, sf::Color color, Vector2f velocity, Vector2f position, int range, AnimationHandlerFactory* animationHandlerFactory) :
			Movable(dimension,color,velocity,position, animationHandlerFactory),
			_range(range),
			_origin(position)
{
	_animationHandlerFactory->getAnimationHandler(ennemy)->attachTexture(this);
}

Ennemy::~Ennemy(){}

void Ennemy::move(float delta)
{
	Movable::move(delta);
	// Invert the direction of the ennemy if it's too far from its origin.
	if (abs(_shape.getPosition().x-_origin.x)>_range)
		_velocity.x=-_velocity.x;
}

void Ennemy::updateAnimation()
{
	_animationHandlerFactory->getAnimationHandler(ennemy)->updateMovable(this);
}